﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;

namespace DAO
{
    public class NhaSanXuatDAO
    {
        public List<shop_nhasanxuat> LayDanhSachNhaSanXuat()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListNSX = from c in EFashionDB.shop_nhasanxuats select c;
            return ListNSX.ToList();

        }

        public shop_nhasanxuat LayNhaSanXuatsTheoMa(int MaNhaSanXuat)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_nhasanxuat select = EFashionDB.shop_nhasanxuats.Single(c => c.MaNhaSanXuat == MaNhaSanXuat);
            return select;
        }

        public void XoaNhaSanXuat(int MaNhaSanXuat)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var nsx = (from c in EFashionDB.shop_nhasanxuats
                       where c.MaNhaSanXuat == MaNhaSanXuat
                       select c);
            EFashionDB.shop_nhasanxuats.DeleteAllOnSubmit(nsx);
            EFashionDB.SubmitChanges();
        }

        public void CapNhatNhaSanXuat(shop_nhasanxuat nsxLinq)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_nhasanxuat nsx = EFashionDB.shop_nhasanxuats.Single(c => c.MaNhaSanXuat == nsxLinq.MaNhaSanXuat);
            nsx.TenNhaSanXuat = nsxLinq.TenNhaSanXuat;
            nsx.ThongTinNhaSanXuat = nsxLinq.ThongTinNhaSanXuat;

            EFashionDB.SubmitChanges();
        }

        public void ThemNhaSanXuat(shop_nhasanxuat nsxLinq)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.shop_nhasanxuats.InsertOnSubmit(nsxLinq);

            EFashionDB.SubmitChanges();
        }

        /************************************************************************************************************        *                          coder: TRAN KINH LY 
         ***********************************************************************************************************/
        public List<shop_nhasanxuat> layNhaSanXuatGioiHan(int iStart, int iLimit)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var nsx = (from c in EFashionDB.shop_nhasanxuats
                       select c).Skip(iStart).Take(iLimit);
            return nsx.ToList();
        }

        public int laySoLuongNhaSanXuat()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            int totalrow = EFashionDB.shop_nhasanxuats.Count();
            return totalrow;
        }

        public List<shop_nhasanxuat> LayNhaSanXuatTheoKhoa(String key_search)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var nsx = from c in EFashionDB.shop_nhasanxuats
                      where c.TenNhaSanXuat.Contains(key_search)
                      select c;
            return nsx.ToList();
        }
        /************************************************************************************************************        *                          coder: TRAN KINH LY 
         ***********************************************************************************************************/

        
       
    }
}
